package com.deli.core.tools;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Type;

import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

public class Utils {

	public static String printInfo(Object object, HttpServletResponse response,Type listType) {
		//如果是Struts2这里可以使用ServletActionContext.getResponse();获取HttpServletResponse对象
		Gson gson = new Gson();
		String result = gson.toJson(object,listType);
		response.setContentType("text/json; charset=utf-8");
		response.setHeader("Cache-Control", "no-cache"); // 取消浏览器缓存
		PrintWriter out = null;
		try {
			out = response.getWriter();
		} catch (IOException e) {
			e.printStackTrace();
		}
		out.print(result);
		out.flush();
		out.close();
		return null;
	}

}